<script setup lang="ts">
import { onMounted } from 'vue';
import { useUserStore } from './stores/user';
import { useRouter } from 'vue-router';

const userStore = useUserStore();
const router = useRouter();

onMounted(async () => {
  if (userStore.token) {
    try {
      await userStore.fetchUserInfo();
      userStore.connectWebSocket();
    } catch (error) {
      console.error('Failed to fetch user info or connect WebSocket:', error);
      // 如果获取用户信息失败，可能是token已过期，我们应该清除状态并重定向到登录页
      userStore.logout();
      router.push('/login');
    }
  }
});
</script>

<template>
  <router-view></router-view>
</template>

<style>
/* 全局样式 */
body {
  margin: 0;
  font-family: Arial, sans-serif;
}
</style>
